package demo.listener.spring;

import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Component;

// 引用关系：MyEventListener——MyCustomEvent
// 引用关系：MyEventPublisher——MyCustomEvent

@Component
public class MyEventPublisher implements ApplicationEventPublisherAware {

    private ApplicationEventPublisher publisher;

    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher publisher) {
        this.publisher = publisher;
    }

    public void publishEvent(String message) {
        MyCustomEvent event = new MyCustomEvent(this, message);
        publisher.publishEvent(event);
    }
}